<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dealer extends Model
{
    protected $guarded = [];

    public function getAllGoodsCount()
    {
        return array_sum([$this->goods_1,$this->goods_2,$this->goods_3,$this->goods_4, $this->goods_5, $this->goods_6]);
    }

    public function getAllMoneyCount()
    {

        $goods = $GLOBALS['goods'];

        $money = 0;
        foreach ($goods as $key => $good) {
            $money += $this->getAttributeValue('goods_'.($key + 1)) * $good->price;
        }

        return $money;
    }

    public function lottery($type)
    {
        $this->is_win = $type;
        $this->save();
    }

    public function getOneMoneyCount($type)
    {
        $goods = $GLOBALS['goods'];
        return $this->getAttributeValue('goods_'.$type) * $goods[$type-1]->price;
    }

}
